LSET Statement ---------------------------------------------------------------------------- Action Moves data from memory to a random-access file buffer (in preparation for a PUT statement), copies one record variable to another, or left-justifies the value of a string in a string variable. Syntax 1 LSET stringvariable$= stringexpression$ Syntax 2 LSET recordvariable1= recordvariable2 Remarks The LSET statement uses the following arguments. ----------------------------------------------------------------------------- Argument Description Argument Description ---------------------------------------------------------------------------- stringvariable$ Usually a random-access file field defined in a FIELD statement, although it can be any string variable. stringexpression$ The value that is assigned to stringvariable$ and is left-justified. recordvariable1 A record variable of any data type. recordvariable2 A record variable of any data type. If stringexpression$ requires fewer bytes than were defined for stringvariable$ in the FIELD statement, the LSET function left-justifies the string in the field ( RSET right-justifies the string). Spaces are used to pad the extra positions. If the string is too long for the field, both LSET and RSET truncate characters from the right. Numeric values must be converted to strings before they are justified with the LSET or RSET statements. You also can use LSET or RSET with a string variable not defined in a FIELD statement to left-justify or right-justify a string in a given field. For example, the following program lines will right-justify the string N$ in a 20-character field. A$=SPACE$(20) RSET A$=N$ This can be useful for formatting printed output. You can use LSET with Syntax 2 to assign one record variable to another. The following example copies the contents of RecTwo to RecOne. TYPE TwoString StrFld AS STRING * 2 END TYPE TYPE ThreeString StrFld AS STRING * 3 END TYPE DIM RecOne AS TwoString, RecTwo AS ThreeString . . . LSET RecOne = RecTwo Notice that LSET is used to assign record variables of differing types. Record variables of the same type also can be assigned using LET. Also, because RecOne is only two bytes long, only two bytes are copied from RecTwo. LSET copies only the number of bytes in the shorter of the two record variables. See Also LET; MKI$, MKL$, MKS$, MKD$, MKC$; PUT (File I-O); RSET Example The following example shows the effects of using LSET and RSET to assign values to fixed- and variable-length strings. DIM TmpStr2 AS STRING * 25 CLS ' Clear screen. ' Use RSET on variable-length string with a value. TmpStr$ = SPACE$(40) PRINT "Here are two strings that have been right and left " PRINT "justified in a 40-character variable-length string." PRINT RSET TmpStr$ = "Right-|" PRINT TmpStr$ LSET TmpStr$ = "|-Left" PRINT TmpStr$ PRINT "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^" PRINT "12345678901234567890123456789012345678901234567890" PRINT " 1 2 3 4 5" ' Use RSET on fixed-length string of length 25. PRINT PRINT PRINT "Here are two strings that have been right and left" PRINT "justified in a 25-character fixed-length string." PRINT RSET TmpStr2 = "Right-|" PRINT TmpStr2 LSET TmpStr2$ = "|-Left" PRINT TmpStr2$ PRINT "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^" PRINT "12345678901234567890123456789012345678901234567890" PRINT " 1 2 3 4 5" Output Here are two strings that have been right and left justified in a 40-character variable-length string. Right-| |-Left ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12345678901234567890123456789012345678901234567890 1 2 3 4 5 Here are two strings that have been right and left justified in a 25-character fixed-length string. Right-| |-Left ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12345678901234567890123456789012345678901234567890 1 2 3 4 5